package top.lixunda.ecommerce.server.user.api.entity.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.user.api.entity.db.UserInfoDO;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户基本公开信息VO
 *
 * @author lixunda
 * @version time:2020/3/14 14:18
 */
@SuppressWarnings("WeakerAccess")
@Data
public class UserPublicInfoVO {

    /**
     * 系统账户id
     */
    @ApiModelProperty("系统账户id")
    private Integer accountId;

    /**
     * 用户昵称，网名
     */
    @ApiModelProperty("用户昵称，网名")
    private String nickname;

    /**
     * 头像图片
     */
    @ApiModelProperty("头像图片")
    private String headImg;

    public static UserPublicInfoVO fromUserInfoDO(UserInfoDO userInfoDO) {
        if (ObjectValidators.isEmpty(userInfoDO)) {
            return null;
        }
        UserPublicInfoVO vo = new UserPublicInfoVO();
        BeanUtils.copyProperties(userInfoDO, vo);
        return vo;
    }

    public static List<UserPublicInfoVO> fromUserInfoDO(List<UserInfoDO> list) {
        if (list == null) {
            return null;
        }
        return list.stream()
                .map(UserPublicInfoVO::fromUserInfoDO)
                .collect(Collectors.toList());
    }
}
